/*
 * Project: Sudoku Hint Engine for Android
 * Copyright (C) 2010-2013 Emanuel Moecklin
 * 
 * Available under the terms of the Lesser General Public License (LGPL)
 */
package com.onegravity.sudoku.solver.accumulator;

import java.util.List;

import com.onegravity.sudoku.solver.core.Hint;
import com.onegravity.sudoku.solver.core.FinalHint;

/**
 * This accumulator intercepts the add() method to check for hints
 * indicating to stop the production of more hints at least until the hint has been applied.
 * @author Emanuel Moecklin
 */
public class FinalHintInterceptor implements HintsAccumulator {
	
	private HintsAccumulator accu;
	private boolean hasFinalHint;
	
	public FinalHintInterceptor(HintsAccumulator accu) {
		this.accu = accu;
		hasFinalHint = false;
	}
	
	@Override
    public void add(Hint hint) throws StopHintProductionException {
		if (hint!=null) {
			if (hint instanceof FinalHint) {
				hasFinalHint = true;
				accu.add(hint);
				throw new StopHintProductionException();
			}
			accu.add(hint);
		}
	}

	@Override
	public List<Hint> getHints() {
		return accu.getHints();
	}
	
	public boolean hasFinalHint() {
		return hasFinalHint;
	}

	public boolean hasHints() {
		List<Hint> hints = accu.getHints();
		return (hints!=null && hints.size()>0);
	}
}